package utils

import (
	"strings"
)

func GetFileNameByFullPath(fullPath string) string {
	innerFullPath := FormatFile(fullPath)

	return innerFullPath[strings.LastIndex(innerFullPath, "/")+1:]
}

func MergePathFile(args ...string) string {
	if len(args) <= 0 {
		return ""
	}

	if len(args) == 1 {
		return args[0]
	}
	if len(args) == 2 {
		return FormatLeftPath(args[0]) + FormatFile(args[1])
	}

	result := FormatLeftPath(args[0])
	for i := 1; i < len(args)-1; i++ {
		result = result + FormatMiddlePath(args[i])
	}
	result = result + FormatFile(args[len(args)-1])
	return result
}

func FormatLeftPath(path string) string {
	return strings.TrimRight(SeparatorConvert(path), "/") + "/"
}

func FormatMiddlePath(path string) string {
	return strings.Trim(SeparatorConvert(path), "/") + "/"
}

func FormatFile(file string) string {
	return strings.Trim(SeparatorConvert(file), "/")
}

func SplitFullPath(fullPath string) []string {
	return strings.Split(strings.Trim(SeparatorConvert(fullPath), "/"), "/")
}

func SeparatorConvert(fullPath string) string {
	return strings.ReplaceAll(fullPath, "\\", "/")
}
